package evocarcassonne.tileseteditor.ui.javafx.managers;

import evocarcassonne.core.board.Tile;
import evocarcassonne.core.utils.Card;
import evocarcassonne.tileseteditor.managers.TileManager;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;

import java.util.HashMap;
import java.util.Map;

/**
 * Owner: Nobpn
 * Date: 09/10/13
 */
public class ConnectionsManager {

    static ConnCheckBox[] cbs;
//    static Map<Tile, boolean[]> tileCombos;

    public static void init() {

//        tileCombos = new HashMap();

        cbs = new ConnCheckBox[11];

        cbs[0] = new ConnCheckBox(0, "Nord - Est", 4, Card.N, Card.E);
        cbs[1] = new ConnCheckBox(1, "Nord - Sud", 5, Card.N, Card.S);
        cbs[2] = new ConnCheckBox(2, "Nord - Ouest", 3, Card.N, Card.W);
//  -----------------
        cbs[3] = new ConnCheckBox(3, "Sud - Est", 2, Card.S, Card.E);
        cbs[4] = new ConnCheckBox(4, "Sud - Ouest", 0, Card.S, Card.W);
//  -----------------
        cbs[5] = new ConnCheckBox(5, "Est - Ouest", 1, Card.W, Card.E);
//  -----------------
        cbs[6] = new ConnCheckBox(6, "Nord - Est - Ouest", -1, Card.N, Card.E, Card.W);
        cbs[7] = new ConnCheckBox(7, "Nord - Est - Sud", -1, Card.N, Card.E, Card.S);
        cbs[8] = new ConnCheckBox(8, "Nord - Ouest - Sud", -1, Card.N, Card.S, Card.W);
        cbs[9] = new ConnCheckBox(9, "Sud - Est - Ouest", -1, Card.S, Card.E, Card.W);
//  -----------------
        cbs[10] = new ConnCheckBox(10, "Nord - Sud - Est - Ouest", -1, Card.N, Card.E, Card.W, Card.S);

    }

    public static void reset() {

        if (cbs == null) {
            return;
        }

        for (ConnCheckBox cb : cbs) {
            cb.setDisable(false);
            cb.setSelected(false);
        }
    }

    public static CheckBox get(int i) {
        return cbs[i];
    }

    private static class ConnCheckBox extends CheckBox {

        private int compatible;

        public ConnCheckBox(final int me, String text, final int comp, final int... cards) {

            super(text);
            this.compatible = comp;


            setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent actionEvent) {

                    System.out.println(this.getClass());


                }
            });


//            CheckBox src = (CheckBox) e.getSource();
//            boolean value = src.isSelected();
//
//            boolean[] values = new boolean[cbs.length];
//
//            for (int i = 0; i < cbs.length; i++) {
//                if (i != comp && i != me) {
//                    cbs[i].setEnabled(!value);
//                    cbs[i].setSelected(false);
//                }
//
//                values[i] = cbs[i].isSelected();
//                tileCombos.put(TileManager.getTile(), values);
//            }
//
//            if (value) {
//                TileManager.addLink(cards);
//            } else {
//                reset();
//                TileManager.resetLinks();
//            }


        }

    }

}